<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="类别" >
        <treeselect style="width: 199px;height: 32px" v-model="queryParams.deviceType" :options="deptOptions" placeholder="请选择所属部门" />
      </el-form-item>
      <el-form-item label="存放位置" >
        <treeselect style="width: 199px;height: 32px" v-model="queryParams.deviceType" :options="deptOptions" placeholder="请选择所属部门" />
      </el-form-item>

      <el-form-item label="设备名称/编号">
        <el-input
          v-model="queryParams.roleName"
          placeholder=""
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item label="关机日期">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="">搜索</el-button>
        <el-button type="success" icon="el-icon-plus" size="mini" @click="cgjhadd">添加</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="roleList" stripe >
      <el-table-column align="center" type="index" label="序号"  width="55"  />
      <el-table-column align="center" label="设备编号" property="jhdh" width="150" > </el-table-column>
      <el-table-column align="center" label="设备名称"   property="biaoti" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column align="center" label="存放位置" property="cglx" :show-overflow-tooltip="true" width="150" ></el-table-column>
      <el-table-column label="记录日期" property="cjrq" align="center"  width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="开机时间" property="cjrq" align="center"  width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="关机时间" property="cjrq" align="center"  width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column  align="center" label="计划停机(min)" property="cjren" :show-overflow-tooltip="true" width="150" ></el-table-column>
      <el-table-column width="150px" align="center" label="异常停机(min)"  property="beizhu" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column width="150px" align="center" label="理论节拍(min)"  property="dqjd" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column width="150px" align="center" label="产量"  property="dqjd" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column width="150px" align="center" label="良品数"  property="dqjd" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column width="150px" align="center" label="稼动时间"  property="dqjd" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column width="150px" align="center" label="稼动率"  property="dqjd" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column width="150px" align="center" label="性能稼动率"  property="dqjd" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column width="150px" align="center" label="良品率"  property="dqjd" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="200">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-edit"
            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            icon="el-icon-delete"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog
      title="编辑运行记录"
      :visible.sync="dialogVisible"
      width="700px">
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="120px">
        <el-form-item label="设备名称" >
          <el-select
            v-model="queryParams.status"
            placeholder="请选择设备名称"
            clearable
          >
            <el-option
              v-for="dict in sbNameArr"
              :key="dict.dictValue"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="设备编号" >
          <el-input
            v-model="queryParams.code"
            placeholder="请输入编号"
            clearable
          />
        </el-form-item>
        <el-form-item label="开机时间" >
          <el-date-picker
            style="width: 200px"
            v-model="queryParams.value12"
            type="date"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="关机时间" >
          <el-date-picker
            style="width: 200px"
            v-model="queryParams.value1"
            type="date"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="异常停机时长" >
          <el-input
            v-model="queryParams.factoryCode"
            placeholder=""
            clearable
          />
        </el-form-item>
        <el-form-item label="	计划停机时长" >
          <el-input
            v-model="queryParams.model"
            placeholder=""
            clearable
          />
        </el-form-item>
        <el-form-item label="理论生产节拍" >
          <el-input
            v-model="queryParams.chargeUser"
            placeholder="请输入负责人"
            clearable
          />
        </el-form-item>
        <el-form-item label="产量" >
          <el-input
            v-model="queryParams.deviceBrand"
            placeholder=""
            clearable
          />
        </el-form-item>
        <el-form-item label="良品数" >
          <el-input
            v-model="queryParams.deviceBrand"
            placeholder=""
            clearable
          />
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role";
  import { treeselect } from "@/api/system/dept";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";

  export default {
    name: "Role",
    components:{
      Treeselect,
    },
    data() {
      return {
        //设备名称
        sbNameArr:[
          { value: '1',label: '进行中'},
          { value: '2',label: '已结束'},
        ],
        //编辑运行记录
        yunxingList:[],
        dialogVisible:false,
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 角色表格数据
        roleList: [
          { jhdh:'CGJH2020000265',biaoti:'测试数据',cglx:'网购',cgsl:'99',jhje:'8888',cjrq:'',cjren:'季明聪',beizhu:'备注测试',dqjd:'当前节点',spzt:'1',spjssj:'2020-10-02'},
          { jhdh:'CGJH2020000264',biaoti:'测试数据',cglx:'网购',cgsl:'99',jhje:'8888',cjrq:'',cjren:'季明聪',beizhu:'备注测试',dqjd:'当前节点',spzt:'2',spjssj:'2020-10-02'},
          { jhdh:'CGJH2020000263',biaoti:'测试数据',cglx:'网购',cgsl:'99',jhje:'8888',cjrq:'',cjren:'季明聪',beizhu:'备注测试',dqjd:'当前节点',spzt:'3',spjssj:'2020-10-02'}
        ],
        // 日期范围
        dateRange: [],
        // 状态数据字典
        statusOptions: [
          { value: '1',label: '进行中'},
          { value: '2',label: '已结束'},
          { value: '3',label: '未提交'},
        ],
        // 数据范围选项
        dataScopeOptions: [
          {
            value: "1",
            label: "全部数据权限"
          },
          {
            value: "2",
            label: "自定数据权限"
          },
          {
            value: "3",
            label: "本部门数据权限"
          },
          {
            value: "4",
            label: "本部门及以下数据权限"
          },
          {
            value: "5",
            label: "仅本人数据权限"
          }
        ],
        // 菜单列表
        menuOptions: [],
        // 列表
        deptOptions: undefined,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          roleName: undefined,
          roleKey: undefined,
          status: undefined,
          checked:true
        },
        // 表单参数
        form: {},
        defaultProps: {
          children: "children",
          label: "label"
        },
      };
    },
    created() {
      this.getTreeselect()

    },
    methods: {
      /** 查询类别下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
      /** 查询角色列表 */
      getList() {
        this.loading = true;
        listRole(this.addDateRange(this.queryParams, this.dateRange)).then(
          response => {
            this.roleList = response.rows;
            this.total = response.total;
            this.loading = false;
          }
        );
      },
      //表格编辑
      handleEdit:function (index,row) {
        console.log(row)
        this.dialogVisible = true
      },
      //删除
      handleDelete:function (index,row) {
        this.$confirm('确认删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      //采购计划
      cgjhadd:function () {
        console.log('tianjia')
        this.dialogVisible = true


      },


    }
  };
</script>
